package com.atguigu.juc.cas;

import java.util.concurrent.atomic.AtomicInteger;

public class CasHallo {
    public static void main(String[] args) {
        //AtomicInteger是一个线程安全的整数类
        AtomicInteger atomicInteger = new AtomicInteger(5);
        System.out.println(atomicInteger.get());
        //compareAndSet     中的两个参数 ： 第一个是预期原值  ，一个是更新值
        System.out.println(atomicInteger.compareAndSet(5,2025) + "\t" + atomicInteger.get());

        System.out.println(atomicInteger.compareAndSet(6,2026)+ "\t" + atomicInteger.get());

        System.out.println(atomicInteger.incrementAndGet()+ "\t" + atomicInteger.get()); //++i
        System.out.println(atomicInteger.getAndIncrement()+ "\t" + atomicInteger.get());//i++

        System.out.println(atomicInteger.addAndGet(2)+ "\t" + atomicInteger.get());
    }
}
